package com.shelf.device.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.ProgressBar;
import android.widget.Toast;

public class SplashScreen extends Activity {
	private ProgressBar mProgress;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);
		final int welcomeScreenDisplay = 5000;
		final int waitFor = 250;

		mProgress = (ProgressBar) findViewById(R.id.splash_progress_bar);
		Thread welcomeThread = new Thread() {

			int wait = 0;

			@Override
			public void run() {
				try {
					super.run();
					while (wait < welcomeScreenDisplay) {
						sleep(waitFor);
						wait += waitFor;
						mProgress.setProgress(wait);
					}
				} catch (Exception e) {
					showToast(e.toString(), Toast.LENGTH_LONG);
				} finally {
					startActivity(new Intent(SplashScreen.this, Login.class));
					finish();
				}
			}
		};

		welcomeThread.start();
	}

	public void showToast(String msg, int duration) {
		Toast toast = Toast.makeText(this, msg, duration);
		toast.setGravity(Gravity.CENTER, 0, 50);
		toast.show();
	}
}
